import { Component, OnInit } from '@angular/core';
import { AxiosService } from '../../axios.service';

@Component({
  selector: 'app-pinjian-process',
  templateUrl: './pinjian-process.component.html',
  styleUrls: ['./pinjian-process.component.scss']
})
export class PinjianProcessComponent implements OnInit {
  listOfData;

  constructor(public axios: AxiosService) { }

  ngOnInit(): void {
    this.getData();
  }

  // 请求数据
  getData() {
    this.axios.axiosPost('QuerySegmentSchedule', { segment: 'pinjian' })
      .then((data) => {
        this.listOfData = data['order'];
        this.listOfData.sort((a, b) => {
          return a.delivery_date > b.delivery_date ? 1 : -1;
        });
        for (let i = 0; i < this.listOfData.length; i++) {
          this.listOfData[i].ng_count = Number(this.listOfData[i].ng_count);
          this.listOfData[i].ok_count = Number(this.listOfData[i].ok_count);
          this.listOfData[i].quatity_total = Number(this.listOfData[i].quatity_total);
          if (this.listOfData[i].check_date !== '' && this.listOfData[i].ok_count == '0' && this.listOfData[i].ng_count == '0') {
            this.listOfData[i].status = '待品檢';
          } else if (this.listOfData[i].check_date !== '' && this.listOfData[i].ng_count != '0' && this.listOfData[i].ok_count < this.listOfData[i].quatity_total) {
            this.listOfData[i].status = '已檢-NG';
          } else {
            this.listOfData[i].status = '';
          }
        }
        console.log(this.listOfData);
      })
      .catch((err) => {
        console.log(err);
      });
  }

}
